<?php
	$linkuser = url_link($username,$ipid,'thanh-vien');
?>
<script type="text/javascript">
// Popup window code
function newPopup(url) {
	popupWindow = window.open(
		url,'popUpWindow','height=300,width=330,left=430,top=23,resizable=yes,scrollbars=yes,toolbar=yes,menubar=no,location=no,directories=no,status=yes')
}
</script>
<div class="block-main">
<div class="breadcrumbs">
	<div xmlns:v="http://rdf.data-vocabulary.org/#" class="cufont">
		<span typeof="v:Breadcrumb"><a property="v:title" href="/">Xem phim</a></span> > Thành viên > 
		<span typeof="v:Breadcrumb">
			<a property="v:title" rel="v:url" title="<?=$fullname;?>" href="<?=$userpag;?>"><?=$username;?></a>
		</span>
	</div>
</div>
<div class="user-contents">
	<ul class="nav_1">
				<li class="payli1">&nbsp;</li>
				<li class="tab_pay <?php if(!$m) echo 'tab_pay_active';?>"><a href="<?=$linkuser?>">Thành viên</a></li>
				<?php if($_SESSION["ipos_userid"] && GOLD_OPEN == '1') { ?>
				<li class="tab_pay"><a href="JavaScript:newPopup('<?=MAIN_URL?>/thanhtoan');">Nạp gold</a></li>
				<li class="tab_pay <?php if($m==1) echo 'tab_pay_active';?>"><a href="<?=$linkuser?>?m=1">Đổi gold</a></li>
				<li class="tab_pay <?php if($m==2) echo 'tab_pay_active';?>"><a href="<?=$linkuser?>?m=2">Lịch sử nạp gold</a></li>
				<li class="tab_pay <?php if($m==3) echo 'tab_pay_active';?>"><a href="<?=$linkuser?>?m=3">Lịch sử dùng gold</a></li>
				<?php } ?>
				<div class="clr"></div> 
	</ul>
    <div class="zmain">
    	<img width="150" class="avatar" src="<?=avatar($avatar);?>" alt="<?=$fullname;?>" />
        <div class="lbox userInfo">
        <?php
			// Nạp gold
		if($_SESSION["ipos_userid"] == $ipid) {
			?>
            <?php
			// lịch sử nạp gold + lịch sử xài gold
			if($m == 2 || $m == 3) {
				if($m == 3)	$wherez	=	"log_type = 0";
				else		$wherez	=	"log_type = 1";
				$log	=	$db->database("gold,log_txt,log_time","log",
											"userid = '".$_SESSION["ipos_userid"]."' and $wherez order by log_time desc");
			?>
            <table class="table" width="770" cellpadding="0" cellspacing="0">
            	<tr>
					<td width="30"  align="center"><strong>STT</strong></td>
                    <td><strong>Thời gian</strong></td>
                    <td><strong>Mô tả</strong></td>
                    <td><strong><?=GOLD;?></strong></td>		
				</tr>
                <? for($i=0;$i<count($log);$i++) { ?>
            	<tr>
					<td align="center"><?=($i+1);?></td>
                    <td><?=(date("G:i:s d/m/Y",$log[$i][2]));?></td>
                    <td><?=($log[$i][1]);?></td>
                    <td><?=(number_format($log[$i][0]));?></td>		
				</tr>
                <? } ?>
            </table>
            <?php
			}
			// kich hoạt tài khoản
			elseif($m == 1){
				include_once("./include/gold.php");
			?>
		<form class="jNice" method="post" onsubmit="return submit_gold();" name="submit">
        <p><span class="lfmn">Chuyển đổi:</span><select name="action">
            	<option value="">Chọn</option>
                <?php
				for($i=0;$i<count($goldarray);$i++) {
					$goldx	=	$goldarray[$i]['gold'];
					$datex	=	$goldarray[$i]['date'];
                	echo '<option value="'.$goldx.'-'.$datex.'">'.(number_format($goldx)).' '.GOLD.' thành '.$datex.' ngày kích hoạt</option>';
				}
				?>
            </select>
        </p>
        <p><span class="lfmn">Nhập mã an toàn:</span><input type="text" name="captcha" />
        <img style="vertical-align: middle;" id="captchaimg" src="captcha.php?rand=<?=rand();?>" /></p>
        <p><span class="lfmn"></span><input type="submit" style="font-size:10pt; cursor:pointer;" name="submit" value="Kích hoạt" class="loginb" /></p>

        </form>
            <?php
			}else {
				// luu thong tin
				if($_POST['submit']) {
						$zpassword		=	htmlchars(stripslashes(trim(urldecode($_POST['password']))));
						$fullname		=	htmlchars(stripslashes(trim(urldecode($_POST['fullname']))));
						$day			=	intval($_POST['day']);
						$month			=	intval($_POST['month']);
						$year			=	intval($_POST['year']);
						$sex			=	intval($_POST['xsex']);
						$birthday		=	"$day-$month-$year";
		
						if($fullname) {
							
							if($avatar != $_POST['avatar']) {
								include_once("./include/upload.php");
									$oldumask = umask(0);
										@mkdir(UPLOAD_DIR."/avatar", 0777);
										@mkdir(UPLOAD_DIR."/avatar/thumb", 0777);
									umask($oldumask);
									$file_EXT			=	get_type($_FILES["upavt"]['name']);
									if(in_array($file_EXT, array('jpg','jpeg','png','gif','JPG','JPEG','PNG','GIF'))) {
										$filename	=	replace($username.'-'.$ipid);
										$fileupload	=	'avatar/'.$filename.'.'.$file_EXT;
										$uploaddir	=	UPLOAD_DIR."/avatar/".$filename.'.'.$file_EXT;
										if(@move_uploaded_file ($_FILES["upavt"]['tmp_name'],$uploaddir)) {
											imagesthumb($uploaddir,$uploaddir,$file_EXT,156);
											$uploadthum	=	UPLOAD_DIR."/avatar/thumb/".$filename.'.'.$file_EXT;
											imagesthumb($uploaddir,$uploadthum,$file_EXT,50);
											cropimages($uploadthum,$uploadthum,$file_EXT,50,50);
											$avatar	=	UPLOAD_FOLDER.'/'.$fileupload;
										}
									}
							}
							
							if($zpassword) {
								$password	=	md5(md5($zpassword).$usercode);
							}
							$db->dbupdate("user","password='$password',
													sex='$sex',
													fullname='$fullname',
													birthday='$birthday',
													avatar='$avatar'","userid = '$ipid'");
							header("Location:".URL_LOAD);
						}
				}
		?>
        <form method="post" name="submit" enctype="multipart/form-data">
        <p><span class="lfmn">Avatar:</span><input type="text" name="avatar" readonly="readonly" value="<?=$avatar;?>" /><span class="file"><input type="file" name="upavt" /></span></p>
        <p><span class="lfmn">Tên tài khoản:</span><input type="text" name="username" readonly="readonly"  value="<?=$username;?>" /></p>
        <p><span class="lfmn">Mật khẩu:</span><input type="password" name="password"/> (Để trống nếu không muốn đổi)</p>
        <p><span class="lfmn">Email:</span><input type="text" readonly="readonly" name="email" value="<?=$email;?>"/></p>
        <p><span class="lfmn">Họ tên:</span><input type="text" name="fullname" value="<?=$fullname;?>"/></p>
        <p class="birthday"><span class="lfmn">Ngày sinh:</span><select name="day">
                                        <? 
										for($i=1;$i<32;$i++) { 
											if($i == $dayx)	$cssday[$i]	=	"selected";
										?>
                                            <option value="<?=$i?>" <?=$cssday[$i]?>><?=$i?></option>
                                        <? } ?>
                                    </select><select name="month">
                                        <? 
										for($i=1;$i<13;$i++) { 
											if($i == $month)	$cssmonth[$i]	=	"selected";
										?>
                                            <option value="<?=$i?>" <?=$cssmonth[$i];?>><?=$i?></option>
                                        <? } ?>
                                    </select><input type="text"  name="year" value="<?=$year;?>" /> (Ngày/Tháng/Năm)
        </p>
        <p><span class="lfmn">Giới tính:</span><select name="xsex">
                                        <? 
										for($i=0;$i<2;$i++) { 
											if($i == $user[0][5])	$cssof[$i]	=	"selected";
										?>
                                            <option value="<?=$i?>" <?=$cssof[$i]?>><?=sexName($i)?></option>
                                        <? } ?>
                                    </select></p>
        <p><span class="lfmn"></span><span class="mode-view"><input type="submit" style="font-size:10pt; cursor:pointer;" name="submit" value="Lưu thông tin"  /></span></p>
        </form>
		<script>
			$('input[type="file"]').change(function(){
					$('input[name="avatar"]').val($(this).val());
			});
        </script>
        <?php
			}
		}else {
		?>
        	<p><span class="lfmn">Họ và tên:</span><?=$fullname;?></p>
            <p><span class="lfmn">Nhóm thành viên:</span><?=$usergroup;?></p>
            <p><span class="lfmn">Ngày tham gia:</span><?=$regdate;?></p>
            <p><span class="lfmn">Giới tính:</span><?=$sex;?></p>
            <p><span class="lfmn">Ngày sinh:</span><?=$birthday;?></p>
        <?php
		}
		?>
        </div>
        <div class="clr"></div>
    </div>
</div>
</div>